﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Wpf2.Models;
using CrystalDecisions.CrystalReports.Engine;
using WPFServices;

namespace Wpf2.Views
{
    /// <summary>
    /// Interaction logic for CrystalReportAddInventory.xaml
    /// </summary>
    public partial class FormCryReOutInvetory 
    {
        readonly ReportDocument _report = new ReportDocument();
        public FormCryReOutInvetory(IEnumerable<Products> listProducts, USER user, Customer cus, PaymentInfomation payment, DateTime orderDate, IDictionary<string, string> param, bool isMarcle)
        {

            InitializeComponent();
            try
            {
                var path = Environment.CurrentDirectory;
                var report = new ReportDocument();
                string link;
                if(isMarcle)
                     link = path.Insert(path.Length, "\\CrystalReport\\CryReMarcleOutInventory.rpt");
                else
                    link = path.Insert(path.Length, "\\CrystalReport\\CryReOutInventory.rpt");
                report.Load(link);
                _report.SetDataSource(listProducts.ToList());


                _report.SetParameterValue("OrderDate", orderDate);
                _report.SetParameterValue("UserID", user.ID_USER);
                _report.SetParameterValue("Address_user", cus.Address+"");
                _report.SetParameterValue("Name_user", cus.CusName + ""); // thêm mới
                _report.SetParameterValue("Phone_user", cus.Phone + "");
                _report.SetParameterValue("OldDebts", payment.OldDebts);
                _report.SetParameterValue("SumOut", payment.SumOut);
                _report.SetParameterValue("TotalAllPayment", payment.TotalPayment);
                _report.SetParameterValue("PrePaid", payment.PrePaid);
                _report.SetParameterValue("Remain", payment.Remain);

                _report.SetParameterValue("StoreName", param["StoreName"]);
                _report.SetParameterValue("Address", param["Address"]);
                _report.SetParameterValue("Phone", param["Phone"]);
                _report.SetParameterValue("Mobile", param["Mobile"]);
                CRViewer.ViewerCore.ReportSource = _report;
            }
            catch (Exception e)
            {

                MessageBox.Show(e.Message);
            }
        }
        
       
    }
}

